#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    FILE *pout;
    FILE *pin1;
    FILE *pin2;
    char ch;
    char ne;

    if((pout = fopen("hello.c", "r")) == NULL)
    {
        printf("fopen failed\n");
        exit(0);
    }
    if((pin1 = fopen("newhello.c", "w")) == NULL)
    {
        printf("fopen failed\n");
        exit(0);
    }
    if((pin2 = fopen("comment.txt", "w")) == NULL)
    {
        printf("fopen failed\n");
        exit(0);
    }
    int flag = 0;

    while (!feof(pout))
    {
        ch = fgetc(pout);
        if(ch == EOF)
            continue;
        if(ch == '/')
        {
            ch = fgetc(pout);
            if(ch == '/')
            {
                while(ch != '\n' && ch != EOF)
                {
                    ch = fgetc(pout);
                    if(ch == EOF)
                        continue;
                    fputc(ch, pin2);
                }
                if(flag)
                    fputc('\n', pin1);
            }
            else if(ch == '*')
            {
                ch = fgetc(pout);
                ne = fgetc(pout);
                while(ch != '*' || ne != '/')
                {
                    fputc(ch, pin2);
                    ch = ne;
                    ne = fgetc(pout);
                }
                fputc('\n', pin2);
                fgetc(pout);
                if(flag)
                    fputc('\n', pin1);
            }
            else
            {
                fputc('/', pin1);
                fputc(ch, pin1);
            }
        }
        else
        {
            flag = 1;
            fputc(ch, pin1);
        }
    }
    fclose(pout);
    fclose(pin1);
    fclose(pin2);
    return 0;
}